package forum.entities;

import javax.validation.constraints.NotNull;
import java.math.BigInteger;

public abstract class Entity  {

    @NotNull
    private BigInteger id;

    Entity (BigInteger id) {
        if (id == null) {
            throw new IllegalArgumentException("Null id");
        }
        this.id = id;
    }

    @Override
    public String toString() {
        return "Entity{" +
                "id=" + id +
                '}';
    }

    public BigInteger getId() {
        return id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Entity entity = (Entity) o;

        if (! id.equals(entity.id)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }
}
